package com.loren.demo13.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.loren.demo13.data_permission.CustomDataPermissionHandler;
import com.loren.demo13.data_permission.CustomDataPermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 数据权限拦截器 - 分页拦截器之前
        CustomDataPermissionHandler customDataPermissionHandler = new CustomDataPermissionHandler();
        CustomDataPermissionInterceptor dataPermissionInterceptor = new CustomDataPermissionInterceptor(customDataPermissionHandler);
        interceptor.addInnerInterceptor(dataPermissionInterceptor);

        // 分页拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
